package com.binance.gateway.app.base.vo;

import com.alibaba.fastjson.JSON;
import com.binance.master.error.GeneralCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
public class CommonRet<T> implements Serializable {

    private static final long serialVersionUID = 7085528143801177645L;

    private static final String SUCCESS = GeneralCode.SUCCESS.getCode();

    @ApiModelProperty(required = true, notes = "错误码，000000000表示成功")
    private String code = SUCCESS;

    @ApiModelProperty(required = true, notes = "当错误码非000000000时，返回错误码对应的信息")
    private String message;

    @ApiModelProperty(required = false, notes = "返回的具体数据信息")
    private T data;

    public CommonRet() {
    }

    public CommonRet(T data) {
        setData(data);
    }

    /**
     * true：表示程序处理完成，没有业务异常 false：表示有业务异常
     *
     * @return
     */
    public boolean isSuccess() {
        return SUCCESS.equals(this.code);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

}
